<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.12"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Nabu-asr: loss_functions.py File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Nabu-asr
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.12 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_5a19dd24bd3679bb79d0ed8fbf6eb6c5.html">nabu</a></li><li class="navelem"><a class="el" href="dir_58864515de009ec37b00c7c6d6449040.html">neuralnetworks</a></li><li class="navelem"><a class="el" href="dir_f13b2a92247e332ea3c0639edb02d314.html">trainers</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">loss_functions.py File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>contains functions to compute the training loss  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:af96921a505526dba7c7caba16d38f2b8"><td class="memItemLeft" align="right" valign="top">def&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="loss__functions_8py.html#af96921a505526dba7c7caba16d38f2b8">nabu.neuralnetworks.trainers.loss_functions.factory</a> (loss_function)</td></tr>
<tr class="memdesc:af96921a505526dba7c7caba16d38f2b8"><td class="mdescLeft">&#160;</td><td class="mdescRight">factory method for the loss function  <a href="loss__functions_8py.html#af96921a505526dba7c7caba16d38f2b8">More...</a><br /></td></tr>
<tr class="separator:af96921a505526dba7c7caba16d38f2b8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2024ac6dd991d2a8d7083b5a60c4f576"><td class="memItemLeft" align="right" valign="top">def&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="loss__functions_8py.html#a2024ac6dd991d2a8d7083b5a60c4f576">nabu.neuralnetworks.trainers.loss_functions.marigin_loss</a> (targets, logits, logit_seq_length, target_seq_length)</td></tr>
<tr class="memdesc:a2024ac6dd991d2a8d7083b5a60c4f576"><td class="mdescLeft">&#160;</td><td class="mdescRight">marigin loss  <a href="loss__functions_8py.html#a2024ac6dd991d2a8d7083b5a60c4f576">More...</a><br /></td></tr>
<tr class="separator:a2024ac6dd991d2a8d7083b5a60c4f576"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a77b97b903c531a8fbff181af1580833a"><td class="memItemLeft" align="right" valign="top">def&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="loss__functions_8py.html#a77b97b903c531a8fbff181af1580833a">nabu.neuralnetworks.trainers.loss_functions.cross_entropy</a> (targets, logits, seq_length)</td></tr>
<tr class="memdesc:a77b97b903c531a8fbff181af1580833a"><td class="mdescLeft">&#160;</td><td class="mdescRight">compute the cross entropy for all sequences in the batch  <a href="loss__functions_8py.html#a77b97b903c531a8fbff181af1580833a">More...</a><br /></td></tr>
<tr class="separator:a77b97b903c531a8fbff181af1580833a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a07eb3b5b62be793ac0cc5df25a5f3777"><td class="memItemLeft" align="right" valign="top">def&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="loss__functions_8py.html#a07eb3b5b62be793ac0cc5df25a5f3777">nabu.neuralnetworks.trainers.loss_functions.sigmoid_cross_entropy</a> (targets, logits, seq_length)</td></tr>
<tr class="memdesc:a07eb3b5b62be793ac0cc5df25a5f3777"><td class="mdescLeft">&#160;</td><td class="mdescRight">compute the sigmnoid cross entropy for all sequences in the batch  <a href="loss__functions_8py.html#a07eb3b5b62be793ac0cc5df25a5f3777">More...</a><br /></td></tr>
<tr class="separator:a07eb3b5b62be793ac0cc5df25a5f3777"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab4486a5ad2d2b39cab59c4a4dd26aeb8"><td class="memItemLeft" align="right" valign="top"><a id="ab4486a5ad2d2b39cab59c4a4dd26aeb8"></a>
def&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="loss__functions_8py.html#ab4486a5ad2d2b39cab59c4a4dd26aeb8">nabu.neuralnetworks.trainers.loss_functions.sum_cross_entropy</a> (targets, logits, logit_seq_length, target_seq_length)</td></tr>
<tr class="memdesc:ab4486a5ad2d2b39cab59c4a4dd26aeb8"><td class="mdescLeft">&#160;</td><td class="mdescRight">cross entropy summed over timesteps <br /></td></tr>
<tr class="separator:ab4486a5ad2d2b39cab59c4a4dd26aeb8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a49dc6024b8259cb1daf111fed0994079"><td class="memItemLeft" align="right" valign="top"><a id="a49dc6024b8259cb1daf111fed0994079"></a>
def&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="loss__functions_8py.html#a49dc6024b8259cb1daf111fed0994079">nabu.neuralnetworks.trainers.loss_functions.average_cross_entropy</a> (targets, logits, logit_seq_length, target_seq_length)</td></tr>
<tr class="memdesc:a49dc6024b8259cb1daf111fed0994079"><td class="mdescLeft">&#160;</td><td class="mdescRight">cross entropy averaged over timesteps <br /></td></tr>
<tr class="separator:a49dc6024b8259cb1daf111fed0994079"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a895cdd774b3b566fdbf48c02a1c01339"><td class="memItemLeft" align="right" valign="top"><a id="a895cdd774b3b566fdbf48c02a1c01339"></a>
def&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="loss__functions_8py.html#a895cdd774b3b566fdbf48c02a1c01339">nabu.neuralnetworks.trainers.loss_functions.average_sigmoid_cross_entropy</a> (targets, logits, logit_seq_length, target_seq_length)</td></tr>
<tr class="memdesc:a895cdd774b3b566fdbf48c02a1c01339"><td class="mdescLeft">&#160;</td><td class="mdescRight">sigmoid cross entropy averaged over timesteps <br /></td></tr>
<tr class="separator:a895cdd774b3b566fdbf48c02a1c01339"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aaa786bde59dd37ef052e67bc8d3b017d"><td class="memItemLeft" align="right" valign="top">def&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="loss__functions_8py.html#aaa786bde59dd37ef052e67bc8d3b017d">nabu.neuralnetworks.trainers.loss_functions.CTC</a> (targets, logits, logit_seq_length, target_seq_length)</td></tr>
<tr class="memdesc:aaa786bde59dd37ef052e67bc8d3b017d"><td class="mdescLeft">&#160;</td><td class="mdescRight">CTC loss.  <a href="loss__functions_8py.html#aaa786bde59dd37ef052e67bc8d3b017d">More...</a><br /></td></tr>
<tr class="separator:aaa786bde59dd37ef052e67bc8d3b017d"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>contains functions to compute the training loss </p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="file_a77b97b903c531a8fbff181af1580833a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#file_a77b97b903c531a8fbff181af1580833a">&sect;&nbsp;</a></span>cross_entropy()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">def nabu.neuralnetworks.trainers.loss_functions.cross_entropy </td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>targets</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>logits</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>seq_length</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>compute the cross entropy for all sequences in the batch </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">targets</td><td>a dictionary of [batch_size x time x ...] tensor containing the targets </td></tr>
    <tr><td class="paramname">logits</td><td>a dictionary of [batch_size x time x ...] tensor containing the logits </td></tr>
    <tr><td class="paramname">seq_length</td><td>a dictionary of [batch_size] vectors containing the sequence lengths</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a dictionarie of vectors of [batch_size] containing the cross_entropy </dd></dl>

</div>
</div>
<a id="file_aaa786bde59dd37ef052e67bc8d3b017d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#file_aaa786bde59dd37ef052e67bc8d3b017d">&sect;&nbsp;</a></span>CTC()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">def nabu.neuralnetworks.trainers.loss_functions.CTC </td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>targets</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>logits</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>logit_seq_length</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>target_seq_length</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>CTC loss. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">targets</td><td>a dictionary of [batch_size x time x ...] tensor containing the targets </td></tr>
    <tr><td class="paramname">logits</td><td>a dictionary of [batch_size x time x ...] tensor containing the logits </td></tr>
    <tr><td class="paramname">logit_seq_length</td><td>a dictionary of [batch_size] vectors containing the logit sequence lengths </td></tr>
    <tr><td class="paramname">target_seq_length</td><td>a dictionary of [batch_size] vectors containing the target sequence lengths</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a scalar value containing the loss </dd></dl>

</div>
</div>
<a id="file_af96921a505526dba7c7caba16d38f2b8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#file_af96921a505526dba7c7caba16d38f2b8">&sect;&nbsp;</a></span>factory()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">def nabu.neuralnetworks.trainers.loss_functions.factory </td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>loss_function</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>factory method for the loss function </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">loss_function</td><td>the required loss function</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a callable loss function </dd></dl>

</div>
</div>
<a id="file_a2024ac6dd991d2a8d7083b5a60c4f576"></a>
<h2 class="memtitle"><span class="permalink"><a href="#file_a2024ac6dd991d2a8d7083b5a60c4f576">&sect;&nbsp;</a></span>marigin_loss()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">def nabu.neuralnetworks.trainers.loss_functions.marigin_loss </td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>targets</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>logits</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>logit_seq_length</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>target_seq_length</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>marigin loss </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">targets</td><td>a dictionary of [batch_size x time x ...] tensor containing the targets </td></tr>
    <tr><td class="paramname">logits</td><td>a dictionary of [batch_size x time x ...] tensor containing the logits </td></tr>
    <tr><td class="paramname">logit_seq_length</td><td>a dictionary of [batch_size] vectors containing the logit sequence lengths </td></tr>
    <tr><td class="paramname">target_seq_length</td><td>a dictionary of [batch_size] vectors containing the target sequence lengths</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a scalar value containing the loss </dd></dl>

</div>
</div>
<a id="file_a07eb3b5b62be793ac0cc5df25a5f3777"></a>
<h2 class="memtitle"><span class="permalink"><a href="#file_a07eb3b5b62be793ac0cc5df25a5f3777">&sect;&nbsp;</a></span>sigmoid_cross_entropy()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">def nabu.neuralnetworks.trainers.loss_functions.sigmoid_cross_entropy </td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>targets</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>logits</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>seq_length</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>compute the sigmnoid cross entropy for all sequences in the batch </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">targets</td><td>a dictionary of [batch_size x time x ...] tensor containing the targets </td></tr>
    <tr><td class="paramname">logits</td><td>a dictionary of [batch_size x time x ...] tensor containing the logits </td></tr>
    <tr><td class="paramname">seq_length</td><td>a dictionary of [batch_size] vectors containing the sequence lengths</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a dictionary of vectors of [batch_size] containing the cross_entropy </dd></dl>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.12
</small></address>
</body>
</html>
